<template>
  <div class="banner container">
    <div class="swiper-container" ref="banner">
      <div class="swiper-wrapper">
        <div
          class="swiper-slide"
          v-for="(item, index) in data"
          :key="index"
          @click="handleClick(index)"
        >
          <img :src="item.image" alt="" />
        </div>
      </div>
      <div class="swiper-pagination"></div>
    </div>
  </div>
</template>


<script setup>
import { onMounted, watch, ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
let props = defineProps(["data"]);
const banner = ref();

let swiper = null;
onMounted(() => {
  // 创建轮播图
  swiper = new Swiper(banner.value, {
    pagination: ".swiper-pagination",
    loop: true,
    autoplayDisableOnInteraction: false,
    autoplay: 3000,
  });
});
// 点击事件
const handleClick = (index) => {
  // 根据索引进行路由导航
  switch (index) {
    case 0:
      router.push("/medical/app");
      break;
    case 1:
      router.push("/medical/appol");
      break;
    case 2:
      router.push("/medical/moder");
      break;
    case 3:
      router.push("/medical/sban");
      break;
    default:
      break;
  }
};
watch(
  () => props.data,
  () => {
    // 更新轮播图
    swiper.update();
    swiper.reLoop();
    swiper.slideTo(1, 0);
  },
  {
    flush: "post",
  }
);
</script>

<style lang="scss" scoped>
@import "@/assets/style/variable.scss";
.banner {
  margin: 10px auto;
  width: 90%;
  height: 140px;
  border-radius: 10px;
  .swiper-container {
    border-radius: 10px;
    width: 100%;
    height: 100%;
    
    img {
      width: 100%;
      height: 100%;
      
    }
  }
}
</style>